{ ------------------------------------------------------------------------------

  DIUclApi.pas -- UCL Compression Library API for Borland Delphi

  This file is part of the DIUcl package.

  Copyright (c) 2003-2013 Ralf Junker - The Delphi Inspiration
  All Rights Reserved.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

  Ralf Junker - The Delphi Inspiration
  <delphi@yunqa.de>
  http://www.yunqa.de/delphi/

  UCL is Copyright (c) 1996-2004 Markus Franz Xaver Johannes Oberhumer
  All Rights Reserved.

  Markus F.X.J. Oberhumer
  <markus@oberhumer.com>
  http://www.oberhumer.com/opensource/ucl/

------------------------------------------------------------------------------ }

unit KRK.Lib.DIUcl.Api;

{$I DICompilers.inc}
{$A+}
{$Z+}

interface

const
  UCL_VERSION_CONST = $010300;

  UCL_E_OK = 0;
  UCL_E_ERROR = -1;
  UCL_E_INVALID_ARGUMENT = -2;
  UCL_E_OUT_OF_MEMORY = -3;

  UCL_E_NOT_COMPRESSIBLE = -101;

  UCL_E_INPUT_OVERRUN = -201;
  UCL_E_OUTPUT_OVERRUN = -202;
  UCL_E_LOOKBEHIND_OVERRUN = -203;
  UCL_E_EOF_NOT_FOUND = -204;
  UCL_E_INPUT_NOT_CONSUMED = -205;
  UCL_E_OVERLAP_OVERRUN = -206;

type
  {$IFNDEF COMPILER_6_UP}
  PCardinal = ^Cardinal;
  {$ENDIF !COMPILER_6_UP}

  ucl_progress_callback_p = ^ucl_progress_callback_t;
  ucl_progress_callback_t = record
    Callback: procedure(TextSize: Cardinal; CodeSize: Cardinal; State: Integer; User: Pointer);
    User: Pointer;
  end;

  ucl_compress_config_p = ^ucl_compress_config_t;

  ucl_compress_config_t = record
    bb_endian: Integer;
    bb_size: Integer;
    max_offset: Cardinal;
    max_match: Cardinal;
    s_level: Integer;
    h_level: Integer;
    p_level: Integer;
    c_flags: Integer;
    m_size: Cardinal;
  end;

function ucl_init: Integer;

function __ucl_init2(v: Cardinal; s1, s2, s3, s4, s5, s6, s7, s8, s9: Integer): Integer;

function ucl_copyright: PAnsiChar;

function ucl_version: Cardinal;

function ucl_version_string: PAnsiChar;

function ucl_version_date: PAnsiChar;

function ucl_output_block_size(const input_block_size: Cardinal): Cardinal;

{$IFDEF CPUX86}

function ucl_nrv2b_99_compress(
  const In_: Pointer;
  in_len: Cardinal;
  Out_: Pointer;
  var out_len: Cardinal;
  cb: ucl_progress_callback_p;
  Level: Integer;
  const conf: ucl_compress_config_p;
  Result: PCardinal): Integer;

function ucl_nrv2b_decompress_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2b_decompress_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2b_decompress_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2b_decompress_safe_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2b_decompress_safe_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2b_decompress_safe_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2b_decompress_asm_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2b_decompress_asm_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2b_decompress_asm_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2b_decompress_asm_safe_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2b_decompress_asm_safe_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2b_decompress_asm_safe_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2b_decompress_asm_fast_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2b_decompress_asm_fast_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2b_decompress_asm_fast_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2b_decompress_asm_fast_safe_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2b_decompress_asm_fast_safe_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2b_decompress_asm_fast_safe_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2b_decompress_asm_small_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2b_decompress_asm_small_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2b_decompress_asm_small_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2b_test_overlap_8(
  const Src: Pointer;
  src_off: Cardinal;
  src_len: Cardinal;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2b_test_overlap_le16(
  const Src: Pointer;
  src_off: Cardinal;
  src_len: Cardinal;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2b_test_overlap_le32(
  const Src: Pointer;
  src_off: Cardinal;
  src_len: Cardinal;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

{$ENDIF CPUX86}

function ucl_nrv2d_99_compress(
  const In_: Pointer;
  in_len: Cardinal;
  Out_: Pointer;
  var out_len: Cardinal;
  cb: ucl_progress_callback_p;
  Level: Integer;
  const conf: ucl_compress_config_p;
  Result: PCardinal): Integer;

function ucl_nrv2d_decompress_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2d_decompress_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2d_decompress_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2d_decompress_safe_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2d_decompress_safe_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2d_decompress_safe_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

{$IFDEF CPUX86}

function ucl_nrv2d_decompress_asm_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2d_decompress_asm_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2d_decompress_asm_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2d_decompress_asm_fast_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2d_decompress_asm_fast_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2d_decompress_asm_fast_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2d_decompress_asm_fast_safe_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2d_decompress_asm_fast_safe_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2d_decompress_asm_fast_safe_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2d_decompress_asm_safe_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2d_decompress_asm_safe_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2d_decompress_asm_safe_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2d_decompress_asm_small_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2d_decompress_asm_small_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2d_decompress_asm_small_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

{$ENDIF CPUX86}

function ucl_nrv2d_test_overlap_8(
  const Src: Pointer;
  src_off: Cardinal;
  src_len: Cardinal;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2d_test_overlap_le16(
  const Src: Pointer;
  src_off: Cardinal;
  src_len: Cardinal;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2d_test_overlap_le32(
  const Src: Pointer;
  src_off: Cardinal;
  src_len: Cardinal;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2e_99_compress(
  const In_: Pointer;
  in_len: Cardinal;
  Out_: Pointer;
  var out_len: Cardinal;
  cb: ucl_progress_callback_p;
  Level: Integer;
  const conf: ucl_compress_config_p;
  Result: PCardinal): Integer;

function ucl_nrv2e_decompress_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2e_decompress_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2e_decompress_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2e_decompress_safe_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2e_decompress_safe_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2e_decompress_safe_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

{$IFDEF CPUX86}

function ucl_nrv2e_decompress_asm_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2e_decompress_asm_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2e_decompress_asm_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2e_decompress_asm_fast_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2e_decompress_asm_fast_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2e_decompress_asm_fast_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2e_decompress_asm_fast_safe_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2e_decompress_asm_fast_safe_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2e_decompress_asm_fast_safe_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2e_decompress_asm_safe_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2e_decompress_asm_safe_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2e_decompress_asm_safe_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2e_decompress_asm_small_8(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2e_decompress_asm_small_le16(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

function ucl_nrv2e_decompress_asm_small_le32(
  const Src: Pointer;
  src_len: Cardinal;
  dst: Pointer;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer; cdecl;

{$ENDIF CPUX86}

function ucl_nrv2e_test_overlap_8(
  const Src: Pointer;
  src_off: Cardinal;
  src_len: Cardinal;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2e_test_overlap_le16(
  const Src: Pointer;
  src_off: Cardinal;
  src_len: Cardinal;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

function ucl_nrv2e_test_overlap_le32(
  const Src: Pointer;
  src_off: Cardinal;
  src_len: Cardinal;
  var dst_len: Cardinal;
  wrkmem: Pointer): Integer;

implementation

type

  C___int8 = System.ShortInt;
  C___int16 = System.SmallInt;
  C___int32 = System.Integer;
  C___int64 = System.Int64;

  C___uint8 = System.Byte;
  C___uint16 = System.Word;
  C___uint32 = System.Cardinal;
  C___uint64 = System.{$IFDEF SUPPORTS_UINT64}UInt64{$ELSE}Int64{$ENDIF};

  C_char = System.AnsiChar;

  C_char_ptr = System.PAnsiChar;
  C_char_ptr_ptr = ^C_char_ptr;
  C_char_ptr_array = array[0..MaxInt div SizeOf(C_char_ptr) - 1] of C_char_ptr;
  C_char_ptr_array_ptr = ^C_char_ptr_array;
  C_char_num = System.ShortInt;

  C_char_num_ptr = ^C_char_num;
  C_double = System.Double;
  C_double_ptr = ^C_double;
  C_float = System.Single;
  C_float_ptr = ^C_float;
  C_int = System.Integer;
  C_int_ptr = ^C_int;
  C_int_array = array[0..MaxInt div SizeOf(C_int) - 1] of C_int;
  C_int_array_ptr = ^C_int_array;

  C_int8_t = C___int8;

  C_int8_t_ptr = ^C_int8_t;

  C_int16_t = C___int16;

  C_int16_t_ptr = ^C_int16_t;

  C_int32_t = C___int32;

  C_int32_t_ptr = ^C_int32_t;

  C_int64_t = C___int64;

  C_int64_t_ptr = ^C_int64_t;

  C_long = System.Integer;
  C_long_ptr = ^C_long;
  C_long_long = System.Int64;
  C_long_long_ptr = ^C_long_long;
  C_long_int = System.Integer;
  C_long_int_ptr = C_long_int;
  C_short = System.SmallInt;
  C_short_ptr = ^C_short;
  C_short_int = System.SmallInt;
  C_short_int_ptr = ^C_short_int;
  C_signed_char = System.ShortInt;
  C_signed_int = System.Integer;
  C_signed_int_ptr = ^C_signed_int;
  C_signed_long = System.Integer;
  C_signed_long_ptr = ^C_signed_long;
  C_signed_short = System.SmallInt;
  C_unsigned = System.Cardinal;
  C_unsigned_ptr = ^C_unsigned;
  C_unsigned_char = System.AnsiChar;

  C_unsigned_char_ptr = System.PAnsiChar;
  C_unsigned_char_ptr_ptr = ^C_unsigned_char_ptr;
  C_unsigned_char_array = array[0..MaxInt div SizeOf(C_unsigned_char) - 1] of C_unsigned_char;
  C_unsigned_char_array_ptr = ^C_unsigned_char_array;
  C_unsigned_char_ptr_array = array[0..MaxInt div SizeOf(C_unsigned_char_ptr) - 1] of C_unsigned_char_ptr;
  C_unsigned_char_ptr_array_ptr = ^C_unsigned_char_ptr_array;
  C_unsigned_char_num = System.Byte;

  C_unsigned_char_num_ptr = ^C_unsigned_char_num;
  C_unsigned_int = System.Cardinal;
  C_unsigned_int_ptr = ^C_unsigned_int;
  C_unsigned___int64 = C___uint64;
  C_unsigned_long = System.Cardinal;
  C_unsigned_long_int = System.Integer;
  C_unsigned_long_long = System.{$IFDEF SUPPORTS_UINT64}UInt64{$ELSE}Int64{$ENDIF};
  C_unsigned_long_ptr = ^C_unsigned_long;
  C_unsigned_short = System.Word;
  C_unsigned_short_ptr = ^C_unsigned_short;
  C_unsigned_short_int = System.Word;
  C_unsigned_short_int_ptr = ^C_unsigned_short_int;

  C_errno_t = C_int;

  C_size_t = {$IFDEF CPUX64}C_unsigned___int64{$ELSE}C_unsigned_int{$ENDIF};
  C_size_t_ptr = ^C_size_t;

  C_uint8_t = C___uint8;

  C_uint8_t_ptr = ^C_uint8_t;

  C_uint16_t = C___uint16;

  C_uint16_t_ptr = ^C_uint16_t;

  C_uint32_t = C___uint32;

  C_uint32_t_ptr = ^C_uint32_t;

  C_uint64_t = C___uint64;

  C_uint64_t_ptr = ^C_uint64_t;

  C_void_ptr = System.Pointer;
  C_void_ptr_ptr = ^C_void_ptr;
  C_void_ptr_array = array[0..MaxInt div SizeOf(C_void_ptr) - 1] of C_void_ptr;
  C_void_ptr_array_ptr = ^C_void_ptr_array;

  C_wchar_t = System.WideChar;

  C_wint_t = C_wchar_t;

  C_wchar_t_ptr = System.PWideChar;

function malloc(Size: C_size_t): C_void_ptr;
var
  MemMgr: System.{$IFDEF COMPILER_10_UP}TMemoryManagerEx{$ELSE}TMemoryManager{$ENDIF};
begin
  if Size > 0 then
    begin

      GetMemoryManager(MemMgr);
      Result := MemMgr.GetMem(Size);
    end
  else
    Result := nil;
end;

procedure Free(Block: C_void_ptr);
var
  MemMgr: System.{$IFDEF COMPILER_10_UP}TMemoryManagerEx{$ELSE}TMemoryManager{$ENDIF};
begin

  if Assigned(Block) then
    begin
      GetMemoryManager(MemMgr);
      MemMgr.FreeMem(Block);
    end;
end;

function memcpy(Dest: C_void_ptr; const Src: C_void_ptr; n: C_size_t): C_void_ptr;
begin
  Result := Dest;
  {$IFDEF DI_Demo} {$ENDIF}
  Move(Src^, Result^, n);
end;

function memset(const s: C_void_ptr; const c: C_int; const n: C_size_t): C_void_ptr;
begin
  Result := s;
  FillChar(Result^, n, c);
end;

{$IFDEF MSWINDOWS}

{$ENDIF MSWINDOWS}

function ucl_init: Integer;
begin
  Result := __ucl_init2(
    UCL_VERSION_CONST,
    SizeOf(SmallInt),
    SizeOf(Integer),
    SizeOf(Integer),
    SizeOf(Cardinal),
    SizeOf(Cardinal),
    -1,
    SizeOf(PAnsiChar),
    SizeOf(Pointer),
    SizeOf(Pointer));
end;

function ucl_output_block_size(const input_block_size: Cardinal): Cardinal;
begin
  Result := input_block_size + input_block_size div 8 + 256;
end;

{$IFDEF CPUX64}{$L ucl_win64\UCL_init}{$ELSE}{$L ucl_win32\UCL_init}{$ENDIF}
{$IFDEF CPUX64}{$L ucl_win64\UCL_ptr}{$ELSE}{$L ucl_win32\UCL_ptr}{$ENDIF}
{$IFDEF CPUX64}{$L ucl_win64\UCL_util}{$ELSE}{$L ucl_win32\UCL_util}{$ENDIF}

{$IFDEF CPUX64}{$L ucl_win64\n2b_99}{$ELSE}{$L ucl_win32\n2b_99}{$ENDIF}
{$IFDEF CPUX64}{$L ucl_win64\n2b_d}{$ELSE}{$L ucl_win32\n2b_d}{$ENDIF}
{$IFDEF CPUX64}{$L ucl_win64\n2b_ds}{$ELSE}{$L ucl_win32\n2b_ds}{$ENDIF}
{$IFDEF CPUX64}{$L ucl_win64\n2b_to}{$ELSE}{$L ucl_win32\n2b_to}{$ENDIF}

{$IFDEF CPUX86}

{$L ucl_win32\n2b_d_f1}
{$L ucl_win32\n2b_d_f2}
{$L ucl_win32\n2b_d_f3}
{$L ucl_win32\n2b_d_f4}
{$L ucl_win32\n2b_d_f5}
{$L ucl_win32\n2b_d_f6}

{$L ucl_win32\n2b_d_n1}
{$L ucl_win32\n2b_d_n2}
{$L ucl_win32\n2b_d_n3}
{$L ucl_win32\n2b_d_n4}
{$L ucl_win32\n2b_d_n5}
{$L ucl_win32\n2b_d_n6}

{$L ucl_win32\n2b_d_s1}
{$L ucl_win32\n2b_d_s2}
{$L ucl_win32\n2b_d_s3}
{$L ucl_win32\n2b_d_s4}
{$L ucl_win32\n2b_d_s5}
{$L ucl_win32\n2b_d_s6}

{$ENDIF CPUX86}

{$IFDEF CPUX64}{$L ucl_win64\n2d_99}{$ELSE}{$L ucl_win32\n2d_99}{$ENDIF}
{$IFDEF CPUX64}{$L ucl_win64\n2d_d}{$ELSE}{$L ucl_win32\n2d_d}{$ENDIF}
{$IFDEF CPUX64}{$L ucl_win64\n2d_ds}{$ELSE}{$L ucl_win32\n2d_ds}{$ENDIF}
{$IFDEF CPUX64}{$L ucl_win64\n2d_to}{$ELSE}{$L ucl_win32\n2d_to}{$ENDIF}

{$IFDEF CPUX86}

{$L ucl_win32\n2d_d_f1}
{$L ucl_win32\n2d_d_f2}
{$L ucl_win32\n2d_d_f3}
{$L ucl_win32\n2d_d_f4}
{$L ucl_win32\n2d_d_f5}
{$L ucl_win32\n2d_d_f6}

{$L ucl_win32\n2d_d_n1}
{$L ucl_win32\n2d_d_n2}
{$L ucl_win32\n2d_d_n3}
{$L ucl_win32\n2d_d_n4}
{$L ucl_win32\n2d_d_n5}
{$L ucl_win32\n2d_d_n6}

{$L ucl_win32\n2d_d_s1}
{$L ucl_win32\n2d_d_s2}
{$L ucl_win32\n2d_d_s3}
{$L ucl_win32\n2d_d_s4}
{$L ucl_win32\n2d_d_s5}
{$L ucl_win32\n2d_d_s6}

{$ENDIF CPUX86}

{$IFDEF CPUX64}{$L ucl_win64\n2e_99}{$ELSE}{$L ucl_win32\n2e_99}{$ENDIF}
{$IFDEF CPUX64}{$L ucl_win64\n2e_d}{$ELSE}{$L ucl_win32\n2e_d}{$ENDIF}
{$IFDEF CPUX64}{$L ucl_win64\n2e_ds}{$ELSE}{$L ucl_win32\n2e_ds}{$ENDIF}
{$IFDEF CPUX64}{$L ucl_win64\n2e_to}{$ELSE}{$L ucl_win32\n2e_to}{$ENDIF}

{$IFDEF CPUX86}

{$L ucl_win32\n2e_d_f1}
{$L ucl_win32\n2e_d_f2}
{$L ucl_win32\n2e_d_f3}
{$L ucl_win32\n2e_d_f4}
{$L ucl_win32\n2e_d_f5}
{$L ucl_win32\n2e_d_f6}

{$L ucl_win32\n2e_d_n1}
{$L ucl_win32\n2e_d_n2}
{$L ucl_win32\n2e_d_n3}
{$L ucl_win32\n2e_d_n4}
{$L ucl_win32\n2e_d_n5}
{$L ucl_win32\n2e_d_n6}

{$L ucl_win32\n2e_d_s1}
{$L ucl_win32\n2e_d_s2}
{$L ucl_win32\n2e_d_s3}
{$L ucl_win32\n2e_d_s4}
{$L ucl_win32\n2e_d_s5}
{$L ucl_win32\n2e_d_s6}

{$ENDIF CPUX86}

{$IFDEF CPUX64}{$L ucl_win64\alloc}{$ELSE}{$L ucl_win32\alloc}{$ENDIF}

function __ucl_init2; external;

function ucl_copyright; external;
function ucl_version; external;
function ucl_version_string; external;
function ucl_version_date; external;

{$IFDEF CPUX86}

function ucl_nrv2b_99_compress; external;

function ucl_nrv2b_decompress_8; external;
function ucl_nrv2b_decompress_le16; external;
function ucl_nrv2b_decompress_le32; external;

function ucl_nrv2b_decompress_safe_8; external;
function ucl_nrv2b_decompress_safe_le16; external;
function ucl_nrv2b_decompress_safe_le32; external;

function ucl_nrv2b_decompress_asm_8; external;
function ucl_nrv2b_decompress_asm_le16; external;
function ucl_nrv2b_decompress_asm_le32; external;

function ucl_nrv2b_decompress_asm_fast_8; external;
function ucl_nrv2b_decompress_asm_fast_le16; external;
function ucl_nrv2b_decompress_asm_fast_le32; external;

function ucl_nrv2b_decompress_asm_fast_safe_8; external;
function ucl_nrv2b_decompress_asm_fast_safe_le16; external;
function ucl_nrv2b_decompress_asm_fast_safe_le32; external;

function ucl_nrv2b_decompress_asm_safe_8; external;
function ucl_nrv2b_decompress_asm_safe_le16; external;
function ucl_nrv2b_decompress_asm_safe_le32; external;

function ucl_nrv2b_decompress_asm_small_8; external;
function ucl_nrv2b_decompress_asm_small_le16; external;
function ucl_nrv2b_decompress_asm_small_le32; external;

function ucl_nrv2b_test_overlap_8; external;
function ucl_nrv2b_test_overlap_le16; external;
function ucl_nrv2b_test_overlap_le32; external;

{$ENDIF CPUX86}

function ucl_nrv2d_99_compress; external;

function ucl_nrv2d_decompress_8; external;
function ucl_nrv2d_decompress_le16; external;
function ucl_nrv2d_decompress_le32; external;

function ucl_nrv2d_decompress_safe_8; external;
function ucl_nrv2d_decompress_safe_le16; external;
function ucl_nrv2d_decompress_safe_le32; external;

{$IFDEF CPUX86}

function ucl_nrv2d_decompress_asm_8; external;
function ucl_nrv2d_decompress_asm_le16; external;
function ucl_nrv2d_decompress_asm_le32; external;

function ucl_nrv2d_decompress_asm_fast_8; external;
function ucl_nrv2d_decompress_asm_fast_le16; external;
function ucl_nrv2d_decompress_asm_fast_le32; external;

function ucl_nrv2d_decompress_asm_fast_safe_8; external;
function ucl_nrv2d_decompress_asm_fast_safe_le16; external;
function ucl_nrv2d_decompress_asm_fast_safe_le32; external;

function ucl_nrv2d_decompress_asm_safe_8; external;
function ucl_nrv2d_decompress_asm_safe_le16; external;
function ucl_nrv2d_decompress_asm_safe_le32; external;

function ucl_nrv2d_decompress_asm_small_8; external;
function ucl_nrv2d_decompress_asm_small_le16; external;
function ucl_nrv2d_decompress_asm_small_le32; external;

{$ENDIF CPUX86}

function ucl_nrv2d_test_overlap_8; external;
function ucl_nrv2d_test_overlap_le16; external;
function ucl_nrv2d_test_overlap_le32; external;

function ucl_nrv2e_99_compress; external;

function ucl_nrv2e_decompress_8; external;
function ucl_nrv2e_decompress_le16; external;
function ucl_nrv2e_decompress_le32; external;

function ucl_nrv2e_decompress_safe_8; external;
function ucl_nrv2e_decompress_safe_le16; external;
function ucl_nrv2e_decompress_safe_le32; external;

{$IFDEF CPUX86}

function ucl_nrv2e_decompress_asm_8; external;
function ucl_nrv2e_decompress_asm_le16; external;
function ucl_nrv2e_decompress_asm_le32; external;

function ucl_nrv2e_decompress_asm_fast_8; external;
function ucl_nrv2e_decompress_asm_fast_le16; external;
function ucl_nrv2e_decompress_asm_fast_le32; external;

function ucl_nrv2e_decompress_asm_fast_safe_8; external;
function ucl_nrv2e_decompress_asm_fast_safe_le16; external;
function ucl_nrv2e_decompress_asm_fast_safe_le32; external;

function ucl_nrv2e_decompress_asm_safe_8; external;
function ucl_nrv2e_decompress_asm_safe_le16; external;
function ucl_nrv2e_decompress_asm_safe_le32; external;

function ucl_nrv2e_decompress_asm_small_8; external;
function ucl_nrv2e_decompress_asm_small_le16; external;
function ucl_nrv2e_decompress_asm_small_le32; external;

{$ENDIF CPUX86}

function ucl_nrv2e_test_overlap_8; external;
function ucl_nrv2e_test_overlap_le16; external;
function ucl_nrv2e_test_overlap_le32; external;

end.

